home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / TIPS / TRANSFER.PAS < prev    next >
Pascal/Delphi Source File  |  1991-10-09  |  5KB  |  196 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal for Windows                     }
  4. {   Tips & Techniques Demo Program               }
  5. {   Copyright (c) 1991 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. program TransferDlg;
  10.  
  11. {$R MyDlg.RES}
  12.  
  13. uses WinTypes, WinProcs, WObjects, Strings;
  14.  
  15. {equate constants defined in the MYDLG.RES resource file}
  16. const
  17.   TextLen      = 18;
  18.   id_ListBox   = 101;
  19.   id_ScrollBar = 102;
  20.   id_CheckBox1 = 103;
  21.   id_CheckBox2 = 104;
  22.   id_CheckBox3 = 105;
  23.   id_Radio0    = 106;
  24.   id_Radio1    = 107;
  25.   id_Radio2    = 108;
  26.   id_InputLine = 109;
  27.   cm_Dialog    = 202;
  28.  
  29. type
  30.   ListBoxRec = record
  31.     List1String: PStrCollection;
  32.     List1Selection: Integer;
  33.   end;
  34.  
  35.   ScrollBarTransferRec = record
  36.     LowValue: Integer;
  37.     HighValue: Integer;
  38.     Position: Integer;
  39.   end;
  40.  
  41.   TransferRecord = record
  42.     ListBoxData: ListBoxRec;
  43.     ScrollBarData: ScrollBarTransferRec;
  44.     Check1, Check2, Check3: Word;
  45.     Radio0, Radio1, Radio2: Word;
  46.     InputEdit: array[0..TextLen - 1] of Char;
  47.   end;
  48.  
  49.   PMyDialog = ^TMyDialog;
  50.   TMyDialog = object(TDialog)
  51.     MyListBox: PListBox;
  52.     MyScrollBar: PScrollBar;
  53.     MyCheckBox1, MyCheckBox2, MyCheckBox3: PCheckBox;
  54.     MyRadio0, MyRadio1, MyRadio2: PRadioButton;
  55.     MyInputLine: PEdit;
  56.     MyOkButton, MyCancelButton: PButton;
  57.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  58.     procedure HandleListBoxMsg(var Message: TMessage);
  59.       virtual id_First + id_ListBox;
  60.     procedure HandleScrollBarMsg(var Message: TMessage);
  61.       virtual id_First + id_Scrollbar;
  62.     procedure SetUpWindow; virtual;
  63.    end;
  64.  
  65.   PMyMainWindow = ^TMyMainWindow;
  66.   TMyMainWindow = object(TWindow)
  67.     MyDialog : PMyDialog;
  68.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  69.     procedure CreateModalDialog(var Message: TMessage);
  70.       virtual cm_First + cm_Dialog;
  71.   end;
  72.  
  73.   TMyDlgApp = object(TApplication)
  74.     procedure InitMainWindow; virtual;
  75.   end;
  76.  
  77. var
  78.   MyTransferRec: TransferRecord;
  79.  
  80. constructor TMyDialog.Init(AParent: PWindowsObject; ATitle: PChar);
  81.  
  82.   procedure FillTransferRecord;
  83.   const
  84.     filled: Boolean = False;
  85.  
  86.   var
  87.      I : byte;
  88.      S : array [0..10] of Char;
  89.  
  90.   begin
  91.    if not filled then { fill the buffer only once with default values}
  92.    begin
  93.      with MyTransferRec.ListBoxData do
  94.      begin
  95.        List1String := New(PStrCollection, Init(10, 5));
  96.        with List1String^ do
  97.          for I := 0 to 9 do
  98.          begin
  99.        LoadString(HInstance, I, S, Sizeof(S));
  100.        Insert(StrNew(S));
  101.           end;
  102.        List1Selection := 5;
  103.      end;
  104.      with MyTransferRec.ScrollBarData do
  105.      begin
  106.        LowValue := 0;
  107.        Highvalue := 9;
  108.        Position := 5;
  109.      end;
  110.      MyTransferRec.Check1 := bf_Checked;
  111.      MyTransferRec.Check2 := bf_Unchecked;
  112.      MyTransferRec.Check3 := bf_Checked;
  113.  
  114.      MyTransferRec.Radio0 := bf_Unchecked;
  115.      MyTransferRec.Radio1 := bf_Checked;
  116.      MyTransferRec.Radio2 := bf_UnChecked;
  117.  
  118.      StrCopy(MyTransferRec.InputEdit, 'Show Up InputLine');
  119.      Filled := True;
  120.    end;
  121.  end;
  122.  
  123. begin
  124.   TDialog.Init(AParent,ATitle);
  125.   New(MyListBox, InitResource(@Self, id_ListBox));
  126.   New(MyScrollBar, InitResource(@Self, id_Scrollbar));
  127.   New(MyCheckBox1, InitResource(@Self, id_CheckBox1));
  128.   New(MyCheckBox2, InitResource(@Self, id_CheckBox2));
  129.   New(MyCheckBox3, InitResource(@Self, id_CheckBox3));
  130.   New(MyRadio0, InitResource(@Self, id_Radio0));
  131.   New(MyRadio1, InitResource(@Self, id_Radio1));
  132.   New(MyRadio2, InitResource(@Self, id_Radio2));
  133.   New(MyInputLine, InitResource(@Self, id_InputLine, TextLen));
  134.   New(MyOkButton, InitResource(@Self, id_Ok));
  135.   New(MyCancelButton, InitResource(@Self, id_Cancel));
  136.  { The Ok and Cancel button ID's are set to 0 and 1.}
  137.  { These ID's are Windows ID_OK and ID_Cancel.}
  138.  { No need to setup methods for OK and Cancel Buttons}
  139.  FillTransferRecord;
  140.  TransferBuffer := @MyTransferRec;
  141. end;
  142.  
  143. procedure TMyDialog.SetUpWindow;
  144. begin
  145.   TDialog.SetUpWindow;
  146.   MyScrollBar^.SetRange(0, 9);
  147. end;
  148.  
  149. procedure TMyDialog.HandleListBoxMsg(var Message: TMessage);
  150. begin
  151.   if Message.LParamHi = lbn_SelChange then
  152.     MyScrollBar^.SetPosition(MyListBox^.GetSelIndex);
  153.   DefWndProc(Message);
  154. end;
  155.  
  156. procedure TMyDialog.HandleScrollBarMsg(var Message:TMessage);
  157. var
  158.   NewPos: Integer;
  159. begin
  160.   if Message.wParam <> sb_ThumbTrack then
  161.     MyListBox^.SetSelIndex(MyScrollBar^.GetPosition)
  162.   else
  163.    DefWndProc(Message);
  164. end;
  165.  
  166. constructor TMyMainWindow.Init(AParent: PWindowsObject; ATitle: PChar);
  167. begin
  168.   TWindow.Init(AParent, ATitle);
  169.   Attr.Menu := LoadMenu(HInstance, 'MyMenu');
  170. end;
  171.  
  172. procedure TMyMainWindow.CreateModalDialog(var Message: TMessage);
  173. var
  174.   ReturnValue: Integer;
  175.  
  176. begin
  177.   MyDialog := New(PMyDialog, Init(@Self, 'MYDIALOG'));
  178.   ReturnValue := Application^.ExecDialog(MyDialog);
  179.   if ReturnValue = id_Cancel then
  180.      MessageBox(HWindow, 'No Data Transfered', 'Cancel', mb_Ok)
  181. end;
  182.  
  183. procedure TMyDlgApp.InitMainWindow;
  184. begin
  185.   MainWindow := New(PMyMainWindow, Init(Nil, 'Dialog App'));
  186. end;
  187.  
  188. var
  189.   MyApp: TMyDlgApp;
  190.  
  191. begin
  192.   MyApp.Init('MyApp');
  193.   MyApp.Run;
  194.   MyApp.Done;
  195. end.
  196.